package com.hinner.controller;

import com.hinner.common.Result;
import com.hinner.configuration.FtpProperties;
import com.hinner.utils.FtpUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/ftp")
public class FtpController {

    @Autowired
    private FtpProperties ftpProperties;

    /**
     * 查询指定路径下所有的文件名
     * @return
     */
    @GetMapping
    public Result into(){
        String ftpHost = ftpProperties.getFtpHost();
        int ftpPort = ftpProperties.getFtpPort();
        String ftpUsername = ftpProperties.getFtpUsername();
        String ftpPassword = ftpProperties.getFtpPassword();
        String path = ftpProperties.getFtpBasePath();
        System.out.println("========>" + ftpHost + " " + ftpPort + " " + ftpUsername +" " + ftpPassword+" " + path);
        List<String> list = FtpUtils.listFileName(ftpHost,ftpPort,ftpUsername,ftpPassword,path);
        return Result.success(list);
    }
}
